"""CreateAdminPermissionTable Migration."""

from masoniteorm.migrations import Migration
import os


class CreateAdminPermissionTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("admin_permissions") as table:
            table.table_comment('访问权限')
            table.increments("id")
            table.string('title', 255, False).comment('标题')
            table.string('uri', 255, True).comment('链接')
            table.unsigned_integer('pid', False).default(0).comment('admin_permission.id,上级')
            table.text('path').nullable().comment('关系树,0/1/2/3')

            table.timestamps()
            if os.getenv("DB_CONNECTION") != "sqlite":
                table.index('pid', 'inx_pid')

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("admin_permissions")
